package com.weilai.common.controller;

import com.weilai.common.model.Medal;
import com.weilai.common.service.MedalService;
import com.weilai.common.utils.StringRandom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created by Song on 2017/6/3.
 */
@Controller
@RequestMapping("/medal")
public class MedalController {
    @Autowired
    MedalService medalService;

    /**
     * 通过用户id修改用户的奖章数量
     * @param medal
     * @return
     */
    @RequestMapping("/updataMedalCount")
    public String updataMedalCount(Model model , @ModelAttribute Medal medal){
        //httpcode 界面用的状态码  200代表成功   400 代表失败  （假的）
         if (medalService.updataMedalCount(medal) == 1){
             model.addAttribute("httpCode","200");
         }else{
             model.addAttribute("httpCode","400");
         }
        return "";
    }

    /**
     * 添加奖章
     * @param model
     * @param medal
     * @return
     */
    @RequestMapping("/addMedal")
    public String addMedal(Model model , @ModelAttribute Medal medal){
        //httpcode 界面用的状态码  200代表成功   400 代表失败  （假的）
        if (medalService.addMedal(medal) == 1){
            model.addAttribute("httpCode","200");
        }else{
            model.addAttribute("httpCode","400");
        }
        return "";
    }

    /**
     * 删除奖章
     * @param model
     * @param medal
     * @return
     */
    @RequestMapping("/delMedal")
    public String delMedal(Model model , @ModelAttribute Medal medal){
        //httpcode 界面用的状态码  200代表成功   400 代表失败  （假的）
        if (medalService.delMedal(medal) == 1){
            model.addAttribute("httpCode","200");
        }else{
            model.addAttribute("httpCode","400");
        }
        return "";
    }


}
